﻿using System;
using System.Collections.Generic;
using System.Data;
using Loki.Utils;

namespace Loki.Data
{
    public abstract class LokiDataProvider : LokiService, IDataProvider
    {
        public IDatabaseAdapter Database { get; set; }

        public virtual void Initialize()
        {
        }

        protected IEnumerable<T> WrapperTransactional<T>(Func<IDbTransaction, IEnumerable<T>> P_Wrapped)
        {
            return Database.WrapperTransactional<T>(P_Wrapped);
        }

        protected T WrapperTransactional<T>(Func<IDbTransaction, T> P_Wrapped)
        {
            return Database.WrapperTransactional<T>(P_Wrapped);
        }

        protected void WrapperTransactional(Action<IDbTransaction> P_Wrapped)
        {
            Database.WrapperTransactional(P_Wrapped);
        }

        protected IEnumerable<T> WrapperTransactional<T>(Func<IDbTransaction, IEnumerable<T>> P_Wrapped, IsolationLevel P_Level)
        {
            return Database.WrapperTransactional<T>(P_Wrapped, P_Level);
        }

        protected T WrapperTransactional<T>(Func<IDbTransaction, T> P_Wrapped, IsolationLevel P_Level)
        {
            return Database.WrapperTransactional<T>(P_Wrapped, P_Level);
        }

        protected void WrapperTransactional(Action<IDbTransaction> P_Wrapped, IsolationLevel P_Level)
        {
            Database.WrapperTransactional(P_Wrapped, P_Level);
        }

        private void RegisterMapper(CommandMapper P_Mapper)
        {
            P_Mapper.Provider = this;
        }
    }
}